#!/usr/bin/env python
# Copyright (c) 2014 Eugene Frolov <efrolov@mirantis.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json

from rdb.old_app.core import storage

rn_storage = storage.RepairNoteStorage()


def prepare_xls(req, prepare_file):
    return rn_storage.prepare_file(file_name=prepare_file)


def load_parse_json(req, file_name, *args, **kwargs):
    x = rn_storage.get_prepare_json(file_name)
    return json.dumps({
        "success": True,
        "tottalCount": len(x),
        "main": x
    })


def commit_import(req, file_name):
    rn_storage.commit_import(file_name)
    return json.dumps({'success': True})
